<!--
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 * No deletion without permission, or be held responsible to law.
 * @author PR
-->
<template>
  <BasicModal
    v-bind="$attrs"
    :title="title"
    :ctype="type"
    :okText="t('打印')"
    @register="registerModal"
    @ok="handleSubmit"
    :minHeight="300"
    :width="500"
    :showOkBtn="true"
    :showCancelBtn="false"
  >
    <div class="ml-4 mt-4">
      <a-textarea
        v-model:value="inputRef"
        placeholder="请输入需打印的编号"
        style="height: 250px; width: 450px"
        ref="ainput"
      />
      <!--  @keyup.enter="showInfo" -->
    </div>
    <PrintModal @register="registerPrintModal" />
  </BasicModal>
</template>
<script lang="ts" setup>
  import { ref, nextTick } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';

  import { useModal } from '/@/components/Modal';
  import { useDrawer } from '/@/components/Drawer';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import PrintModal from '/@/components/print/printModal.vue';

  const emit = defineEmits(['success', 'register']);
  const { t } = useI18n('extd.bill.extdBill');
  const { showMessage, showMessageModal } = useMessage();

  const fileList = ref([]);
  const enterCount = ref(0);
  let inputRef = ref<string>('');
  let ainput = ref<any>(null);
  let title = ref<any>(null);
  let type = ref<any>(null);

  const [registerModal, { setModalProps, closeModal }] = useModalInner((data) => {
    inputRef.value='';
    title.value = data.title;
    type.value = data.type;
    ainput.value.focus();
  });
  const [registerPrintModal, { openModal: openPrintModal }] = useModal();


  async function handleSubmit() {
    if(!inputRef.value){
      showMessage('请填写打印内容！！')
      return false
    }


    let lines = inputRef.value.split(/[(\r\n)\r\n]+/);
    lines.forEach((item, index) => {
      // 删除空项
      if (item === '') {
        lines.splice(index, 1);
      }
    });
    let ids = lines.join(',');
    if (type.value == '1') {
      let obj = {
        title: '客户打印',
        ids: ids,
        height: '0.8',
        width: '0.6',
        fileName: 'printCus',
      };
      openPrintModal(true, obj);
      setTimeout(closeModal);
    }
    if (type.value == '2') {
      let obj = {
        title: '供应商打印',
        ids: ids,
        height: '0.8',
        width: '0.6',
        fileName: 'printVen',
      };
      openPrintModal(true, obj);
      setTimeout(closeModal);
    }
  }
</script>

<style>
  .ant-btn-error {
    /* margin-right: 10px; */
    float: right;
  }
  .tips-success {
    color: green;
    font-size: 20px;
  }

  .tips-error {
    color: red;
    font-size: 20px;
  }
</style>
